<include file="../Public/_header.html" />
<div class="so_main">
	
	<!-------- 搜索开始 -------->
		  <div id="search_div">
		  	<div class="page_tit">
		  		批量发送礼券
		  	</div>
		
				<div class="sform">
					<form method="post" id="searchForm">
						<dl>
							<span>录入批量发送基本信息</span>
							
					      	<span>上架商品ID：</span>
					        <input id="input_shelf_id" type="text" value="10025"><input type="button" value="查看" onclick="showshelf()">
					        <span id="show_shelf" class='hidden'></span>
					      	<span>代金券码：</span>
					        <input id="input_passcode" type="text" value="1324571779793072" >
					        <span>发送方式：</span><select style="height: 24px; width: 100px;" class="inputText" id="send_format">
										                    <option selected="" value="sms">短信发送</option>
										                    <!-- option value="mms">彩信发送</option -->
										                </select>
					    </dl>
					</form>
			  </div>
		  </div>
		  <!-------- 搜索结束 -------->
		  
		  <div style="width:1900px;">
		  	<div style="width:700px;float:left;">
		  		<textarea id="info_text" style="width:700px;height:650px;font-size:12px;">
		  		13810388527|进程|13810388526|成光1|爱你很爱你1
13426349300|进程|01012345678|成光2|爱你很爱你2
13810388527|进程|13810388521|成光3|爱你很爱你3
13426349300|进程|--------|成光4|爱你很爱你4
		  		</textarea>
		  		<input type="button" class="btn_b" value="解析" onclick="doparseinfo()" />
		  	</div>
		  	
		  	<div class="list" style="width:1180px;float:right;">
		  		<span id="alert"></span>
		  		<table id="send_info_table" width="100%">
		  			<tr>
		  				<th width="30px"></th>
		  				<th width="150px">送礼人</th>
		  				<th class="line_l" width="150px">手机</th>
		  				<th class="line_l" width="150px">收礼人</th>
		  				<th class="line_l" width="150px">手机</th>
		  				<th class="line_l">附言</th>
		  				<th class="line_l" width="150px">发送结果</th>
		  			</tr>
		  		</table>
		  	</div>
		  </div>
</div>
<div class="clear"></div>
<form method="post" id="orderform">
					<input 	type='hidden' id='shelf_id' name='shelf_id'
					 				value="" >
					<input 	type='hidden' id='receiver_no' name='receiver_no'
					 				value="" >
					<input 	type='hidden' id='receiver_data' name='receiver_data'
					 				value="" >
					<input 	type='hidden' id='sender_name' name='sender_name'
					 				value="" >
					<input 	type='hidden' id='sender_mobile' name='sender_mobile'
					 				value="" >
					<input 	type='hidden' id='send_format' name='send_format'
					 				value="" >
					<input 	type='hidden' id='txt_content' name='txt_content'
					 				value="" >
					<input 	type='hidden' id='ccpcode' name='ccpcode'
					 				value="" >
					 				
					<!--  
					<input type='hidden' name='smsdata' id='smsdata' value="">
					<input type='hidden' name='cardcontent' id='cardcontent' value="">
					-->
			</form>
<style>
.tmp_alert_bg{
	background-color: #F7BE81;
}
</style>
<script>
function showshelf(){
	var shelf_id = $('#input_shelf_id').val();	
	$.ajax({      
	    url: "{:U('Admin://Tool/getshelf')}",      
	    type:'post', //数据发送方式  
	    data:{ 	shelf_id : shelf_id	} ,   
	    dataType:'json', //接受数据格式      
	    error:function(txt){     
	          	$('#show_shelf').html('发生错误');
	          	$('#show_shelf').show();
	       },     
	    async: true ,//同步方式     shelf_out_price
	    success: function(json_){
	    	if(json_['status']==1){
	    		$('#show_shelf').html("["+json_['data']['partner_title']+"]"+json_['data']['goods_title']+"("+json_['data']['shelf_out_price']+"元)");
	          	$('#show_shelf').show();
	    	}else{
	    		$('#show_shelf').html('不存在');
	          	$('#show_shelf').show();
	    	}
	    }  
	}); 
}
var title_html_ = '<tr>   <th width="20px"></th>'
						+'<th width="80px">收礼人手机</th>'
						+'<th class="line_l" width="80px">收礼人姓名</th>'
						+'<th class="line_l" width="80px">送礼人手机</th>'
						+'<th class="line_l" width="80px">送礼人姓名</th>'
						+'<th class="line_l" width="30px">数量</th>'
						+'<th class="line_l" width="70px">日期</th>'
						+'<th class="line_l" width="30px">小时</th>'
						+'<th class="line_l" width="30px">格式</th>'
						+'<th class="line_l">附言</th>'
						+'<th class="line_l" width="70px">操作</th>'
						+'<th class="line_l" width="150px">发送结果</th>'
						+'</tr>';
function doparseinfo(){
	var info_ = $('#info_text').val();
	var ary_info_ = info_.split("\n");
	var html_=title_html_;
	var will_send_no = 0;
	for( var i = 0 ; i< ary_info_.length ; i++ ){
		var temp_ = ary_info_[i].split("|");
		if(temp_.length==5){
			will_send_no++;
			html_ = html_+"<tr id='valid_tr'>"
					+"<td><input type='checkbox' value='y' id='checkbox'></td>"
					+"<td id='reveiver_mobile'>"+temp_[0]+"</td><td id='reveiver_name'>"+temp_[1]+"</td><td id='sender_mobile'>"+temp_[2]+"</td><td id='sender_name'>"+temp_[3]+"</td>"
					+"<td id='send_no'>"+1+"</td><td id='send_date'><?php echo date( 'Y-m-d',time() );?></td><td id='send_hour'>0</td><td id='send_format'>sms</td>"
					+"<td id='txt_content'>"+temp_[4]+"</td>"
					+"<td><input type='button' class='btn_b' onclick='dosendone(this)' id='btn_dosend' value='发送' /><input type='button' id='btn_sending' class='btn_w hidden' value='.....' /></td>"+
					"<td id='result'></td></tr>";
		}
	}
	//alert(html_);
	$('#alert').html("左侧"+ary_info_.length+"条，右侧"+will_send_no+"条！");
	//var ary_info_ = info_.split("|");
	$('#send_info_table').html(html_);
}


function getOneAndCheck(Jtr){
	var receiver_data = '';//数据以','分割，每个接受者用':'分割。
	var ifhaserror 		= false;
	//ifneedalert 	= false;
	var result = true;
	var receiver_no = 0;
	var reveiver_mobile = Jtr.find('#reveiver_mobile').text();
	if(reveiver_mobile=='')return result;
	
	var fg_ = '';
	var tmp_data = fg_+reveiver_mobile+','+Jtr.find('#send_no').text()+','+
						 Jtr.find('#send_date').text()+','+Jtr.find('#send_hour').text();
	//reveiver_mobile  send_no  send_date  send_hour
	receiver_data = receiver_data + tmp_data;
	receiver_no = receiver_no+1;
	var sender_mobile = Jtr.find('#sender_mobile').text();
		
	var sender_name = Jtr.find('#sender_name').text();
	//选择录入多个手机号码，只录入则通过验证
	if(sender_name==''){sender_name = '神秘人物';}
	
	if(result==true){
		var send_format = Jtr.find('#send_format').text();
		var txt_content = Jtr.find('#txt_content').text();
		/** 设置上传数据 **/
		$('#orderform').find('#receiver_no').val(receiver_no);
		$('#orderform').find('#receiver_data').val(receiver_data);
		$('#orderform').find('#sender_name').val(sender_name);
		$('#orderform').find('#sender_mobile').val(sender_mobile);
		$('#orderform').find('#send_format').val(send_format);
		$('#orderform').find('#txt_content').val(txt_content);
		$('#orderform').find('#ccpcode').val($('#input_passcode').val());
		
	}
	return result;
}
function dosendone(this_){
	$(this_).hide();
	var Jtd = $(this_).parent();
	Jtd.find('#btn_sending').show();
	var Jtr = $(this_).parent().parent();
	//alert(Jtr.find('input[id="checkbox"]').attr('checked'));btn_dosend
	//if(Jtr.find('input[id="checkbox"]').attr('checked')){
				if(getOneAndCheck(Jtr)){
							$.ajax({      
							    url: "{:U('Admin://Tool/doSend')}" ,      
							    type:'post', //数据发送方式  
							    data:{ 	shelf_id		: $('#input_shelf_id').val(),			//上架ID。
										receiver_no		: $('#orderform').find('#receiver_no').val(),		//接收者总数
										receiver_data	: $('#orderform').find('#receiver_data').val(),	//接收者数据
										sender_name		: $('#orderform').find('#sender_name').val(),	//送礼者名称
										sender_mobile	: $('#orderform').find('#sender_mobile').val(),	//送礼者电话号码
										send_format		: $('#orderform').find('#send_format').val(),	//sms=短信发送  mms=彩信发送
										txt_content		: $('#orderform').find('#txt_content').val(),		//短信内容。
										ccpcode			: $('#orderform').find('#ccpcode').val()	//支付的优惠券
									} ,   
								async: false ,
							    //dataType:'html', //接受数据格式
							    dataType:'html',
							    error:function(txt){     
							          	Jtr.find('#result').html(txt);
							       },     
							    async: true ,//同步方式     
							    success: function(txt){ 
							    		alert(txt);
							    		//var myDate = new Date();
							    		var objs	=	eval('(' + txt + ')');
							    		Jtr.find('#result').html(objs.msg);
							    }  
							}); 
				}
	//}
}

function dobatchsend(){
	$('#send_info_table').find('tr[id="valid_tr"]').each( function(i, tr){
			var Jtr = $(tr);
			//alert(Jtr.find('input[id="checkbox"]').attr('checked'));
			if(Jtr.find('input[id="checkbox"]').attr('checked')){
						if(getOneAndCheck(Jtr)){
									$.ajax({      
									    url: "{:U('Admin://Tool/doSend')}" ,      
									    type:'post', //数据发送方式  
									    data:{ 	shelf_id		: $('#input_shelf_id').val(),			//上架ID。
												receiver_no		: $('#orderform').find('#receiver_no').val(),		//接收者总数
												receiver_data	: $('#orderform').find('#receiver_data').val(),	//接收者数据
												sender_name		: $('#orderform').find('#sender_name').val(),	//送礼者名称
												sender_mobile	: $('#orderform').find('#sender_mobile').val(),	//送礼者电话号码
												send_format		: $('#orderform').find('#send_format').val(),	//sms=短信发送  mms=彩信发送
												txt_content		: $('#orderform').find('#txt_content').val(),		//短信内容。
												ccpcode			: $('#orderform').find('#ccpcode').val()	//支付的优惠券
											} ,   
										async: false ,
									    //dataType:'html', //接受数据格式
									    dataType:'html',
									    error:function(txt){     
									          	Jtr.find('#result').html(txt);
									       },     
									    async: true ,//同步方式     
									    success: function(txt){ 
									    		var myDate = new Date();
									    		var objs	=	eval('(' + txt + ')');
									    		Jtr.find('#result').html(objs.msg+myDate.getTime());
									    }  
									}); 
						}
			}
	});
}
</script>

<include file="../Public/_footer.html" />